package com.puzzlebazar.client.squaregrid.view;

import com.puzzlebazar.client.util.Vec2i;

public class EdgeHighlighterBasic implements EdgeHighlighter {

	private final DrawableLayer layer;
	private final String style;
	private final String name;
	
	private int pixelSize = 5;		

	/**
	 * Create an object that is able to highlight edges of a square grid using
	 * a standard square highlight.
	 * 
	 * @param layer The layer into which to put drawables resulting from highlighting
	 * @param style The style to use for highlighting  (can be a space separated list)
	 * @param name The name to use for highlighting drawables
	 */
	public EdgeHighlighterBasic( DrawableLayer layer, String style, String name ) {
		this.layer = layer;
		this.style = style;
		this.name = name;
	}
	
	@Override
	public void highlightHorizontalEdge(Vec2i loc) throws Exception {
		DrawableUtils.addEdge( loc, new Vec2i(loc.x+1,loc.y), layer, style, name.concat( "-horiz" ), pixelSize, true);
	}

	@Override
	public void highlightVerticalEdge(Vec2i loc) throws Exception {
		DrawableUtils.addEdge( loc, new Vec2i(loc.x,loc.y+1), layer, style, name.concat( "-vert" ), pixelSize, true);
	}

	@Override
	public void unhighlightHorizontalEdge(Vec2i loc) throws Exception {
		DrawableUtils.removeEdge( loc, new Vec2i(loc.x+1,loc.y), layer, name.concat( "-horiz" ) );
	}

	@Override
	public void unhighlightVerticalEdge(Vec2i loc) throws Exception {
		DrawableUtils.removeEdge( loc, new Vec2i(loc.x,loc.y+1), layer, name.concat( "-vert" ) );
	}

	@Override
	public void unhighlightAllEdges() {
		layer.removeDrawable(name.concat( "-horiz" ));
		layer.removeDrawable(name.concat( "-vert" ));
	}

	/**
	 * Sets the size, in pixel, of the highlighted edges
	 * 
	 * @param pixelSize The size, in pixel
	 */
	public void setPixelSize( int pixelSize ) {
		this.pixelSize = pixelSize;
	}

}
